package com.ma.controller;

import com.baomidou.mybatisplus.annotation.TableField;
import com.ma.entity.Admin;
import com.ma.entity.Student;
import com.ma.entity.Teacher;
import com.ma.entity.Team;
import com.ma.server.AdminServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ProjectName: project
 * @Package: com.ma.controller
 * @ClassName: AdminCon
 * @Author: YHHHH
 * @Description: 管理员
 * @Date: 2021/4/7 23:56
 * @Version: 1.0
 */
@RestController
@CrossOrigin
public class AdminCon {

    @Autowired
    private AdminServer adminServer;



    @PostMapping("/admin/adminLogin")
    public Admin adminLogin(@RequestBody Admin admin){
        System.out.println(admin);
        Admin adminLogin = adminServer.findAdmin(admin);
        System.out.println(adminLogin);
        System.out.println(adminLogin == null);
        if (adminLogin==null){
            return null;
        }
        return adminLogin;
    }


    /*
    新建学生
     */
    @PostMapping("/admon/addStudent")
    public String addStudent(@RequestBody Student student){
        System.out.println(student);
        Integer integer = adminServer.addStudent(student);
        if (integer!=0){
            return "200";
        }
        return "500";
    }
    /*
    查出所有的学生
     */
    @GetMapping("/admin/findAllStudents")
    public List<Student> findAll(){
        List<Student> addStudents = adminServer.findAllStudents();
        return addStudents;
    }
    /*
    删除学生
     */
    @GetMapping("/admin/deleteStudents")
    @Transactional
    public String deleteStudents(@RequestParam("number")String number){
        Integer integer = adminServer.deleteStudents(number);
        return "200";
    }

    @GetMapping("/admin/findAllTeacher")
    public List<Teacher> findAllTeacher(){
        List<Teacher> addTeacher = adminServer.findAllTeacher();
        return addTeacher;
    }
    @PostMapping("/admon/addTeacher")
    public String addTeacher(@RequestBody Teacher teacher){
        System.out.println(teacher);
        Integer integer = adminServer.addTeacher(teacher);
        if (integer!=0){
            return "200";
        }
        return "500";
    }
}
